package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.FileReview;
import com.amsp.oa.oademo.service.FileReviewService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Api(tags = "文件会审管理")
@RestController
@RequestMapping("/api/file-review")
public class FileReviewController {

    @Autowired
    private FileReviewService fileReviewService;

    @ApiOperation("分页查询文件会审")
    @GetMapping("/page")
    public ResponseEntity<IPage<FileReview>> getPage(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String keyword) {
        return ResponseEntity.ok(fileReviewService.getPage(current, size, keyword));
    }

    @ApiOperation("根据ID获取文件会审详情")
    @GetMapping("/{id}")
    public ResponseEntity<FileReview> getById(@PathVariable Long id) {
        return ResponseEntity.ok(fileReviewService.getDetailById(id));
    }

    @ApiOperation("保存或更新文件会审")
    @PostMapping("/save")
    public ResponseEntity<Boolean> saveOrUpdate(@RequestBody FileReview fileReview) {
        return ResponseEntity.ok(fileReviewService.saveOrUpdateWithDepartments(fileReview));
    }

    @ApiOperation("删除文件会审")
    @DeleteMapping("/{id}")
    public ResponseEntity<Boolean> delete(@PathVariable Long id) {
        return ResponseEntity.ok(fileReviewService.removeById(id));
    }
}